package com.keven.dp.prototype;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Prototype implements Cloneable,Serializable{
	private static final long serialversionUID=1l;
	private String string;
	private SerializableObject obj;
	
	//潜复制
	public Object clone()throws CloneNotSupportedException{
		Prototype proto =(Prototype)super.clone();
		return proto;
	}
	
	public Object  deepClone() throws IOException,ClassNotFoundException {
		ByteArrayOutputStream bos=new ByteArrayOutputStream();
		ObjectOutputStream oos=new ObjectOutputStream(bos);
		oos.writeObject(this);
		
		ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());
		ObjectInputStream ois= new ObjectInputStream(bis);
		return ois.readObject();
	}
	
	public String getString(){
		return string;
	}
	public void setString (String string) {
		this.string=string;
	}
	public Serializable getObj() {
		return obj;
	}
	public void setObj(SerializableObject obj) {
		this.obj=obj;
	}
	
}
class SerializableObject implements Serializable{
	private static  final long seialVersionUID=1l;
}
